@ECHO off

SET Build=
SET BuildData=
SET BuildAll=
SET SP_HW=SDS

if %3.==ADS. SET SP_HW=ADS
if %3.==/a.   SET Build=a
if %3.==\a.   SET Build=a
if %3.==/A.   SET Build=a
if %3.==\A.   SET Build=a
if %3.==/d.   SET BuildData=d
if %3.==\d.   SET BuildData=d
if %3.==/D.   SET BuildData=d
if %3.==\D.   SET BuildData=d
if %3.==/?.   goto :Usage
if %3.==\?.   goto :Usage
if %3.==-?.   goto :Usage
if %3.==?.    goto :Usage

if %2.==ADS. SET SP_HW=ADS
if %2.==/a.   SET Build=a
if %2.==\a.   SET Build=a
if %2.==/A.   SET Build=a
if %2.==\A.   SET Build=a
if %2.==/d.   SET BuildData=d
if %2.==\d.   SET BuildData=d
if %2.==/D.   SET BuildData=d
if %2.==\D.   SET BuildData=d
if %2.==/?.   goto :Usage
if %2.==\?.   goto :Usage
if %2.==-?.   goto :Usage
if %2.==?.    goto :Usage

if %1.==ADS. SET SP_HW=ADS
if %1.==/a.   SET Build=a
if %1.==\a.   SET Build=a
if %1.==/A.   SET Build=a
if %1.==\A.   SET Build=a
if %1.==/d.   SET BuildData=d
if %1.==\d.   SET BuildData=d
if %1.==/D.   SET BuildData=d
if %1.==\D.   SET BuildData=d
if %1.==/?.   goto :Usage
if %1.==\?.   goto :Usage
if %1.==-?.   goto :Usage
if %1.==?.    goto :Usage

if %Build%. ==a. SET BuildAll=/a

:CONTINUE

REM -----  PREPARE DESTINATION DIRECTORY STRUCTURE

@echo *********************
@echo Executing Project.bat
@echo *********************

REM -----  THIS BATCH FILE ASSUMES IT IS RUN FROM THE .../Project/<Host> level
REM -----  of the SoftPay Directory Structure where the <HOST>.DSP & <HOST>.DSW reside.

@call project.bat

REM -----  MOVE TO CORRECT DIRECTORY

cd %SP_ROOT%\Projects\%SP_PROJ%\Bld

@echo ****************************************************
@echo Preparing Environment for SP2000 Project %SP_VER%-%SP_PROJ% 
@echo Build for Output Directory %SPOUTDIR%-%SP_HW%
REM Note SPOUTDIR may be set in your Environment and not
REM updated by PROJECT.BAT batch file above.
REM Please make sure it is set properly for the project you are
REM attempting to build.
@echo ****************************************************

if exist %SP_ROOT%\Output\%SP_HW%\%SPOUTDIR%\nul goto :DESTDIRDONE

@echo ******************************************************
@echo Creating SP2000 Download Directory structure and files
@echo ******************************************************

if not exist %SP_ROOT%\Output\nul md %SP_ROOT%\Output
md %SP_ROOT%\Output\%SPOUTDIR%\%SP_HW%
@echo Creating %SP_ROOT%\Output\%SPOUTDIR%\%SP_HW%
md %SPFILES%
@echo Creating %SPFILES%
md %SPDLD%
@echo Creating %SPDLD%
md %SPEXPORT%
@echo Creating %SPEXPORT%

REM copy %SPTOOLS%\DDL.EXE  %SPDLD%\*.*
REM copy %SPTOOLS%\MakeDir.exe %SPDLD%\*.*
REM copy %SPTOOLS%\Zip.exe %SPDLD%\*.*
REM copy %SPTOOLS%\add_trlr.exe %SPDLD%\*.*

:DESTDIRDONE

@echo ******************************************
@echo Creating Required SoftPay Base Directories
@echo ******************************************

if exist %DBG_DIR%\nul goto :DEBUGDONE
md %DBG_DIR%
@echo Creating %DBG_DIR%
:DEBUGDONE

if exist %CFG_DIR%\nul goto :CFGDONE
md %CFG_DIR%
@echo =====================BUILD BUILD BUILD BUILD BUILD BUILD BUILD BUILD
@echo Creating %CFG_DIR%
:CFGDONE
SET FILE=TXT
if not exist %CFG_DIR%\%FILE%\nul md %CFG_DIR%\TXT
@echo Creating %CFG_DIR%\TXT


if not exist %CFG_DIR%\%FILE%\nul md  %CFG_DIR%\MSG
@echo Creating %CFG_DIR%\MSG

if not exist %CFG_DIR%\%FILE%\nul nd %CFG_DIR%\FLD
@echo Creating %CFG_DIR%\FLD





@echo **************************************
@echo Copying Required SoftPay Config Files
@echo **************************************
REM copy %SRC_ROOT%\INCLUDE\gdcfg.h %CFG_DIR%\*.*
if exist %OBJ_DIR%\nul goto :OBJDONE
md %OBJ_DIR%
@echo Creating %OBJ_DIR%
:OBJDONE

if exist %LIB_DIR%\nul goto :LIBDONE
@echo Creating %LIB_DIR%
md %LIB_DIR%
:LIBDONE

if %BuildAll%.==. goto :LIBDONE2
@echo **************************************
@echo Copying Required SoftPay Library Files
@echo **************************************
REM copy %SRC_ROOT%\EMV\*.a %LIB_DIR%\*.*
:LIBDONE2

@echo ***********************************
@echo Copying Required SoftPay Base Files
@echo ***********************************

REM copy %ACT2000%\%ACT_VER%\Output\Files\ShLib1\Debug\act.lib %SPFILES%\*.*
copy %VFSDK%\%SDK_VER%\bin\dbmon.out %SPFILES%\*.*
REM copy %VFSDK%\%SDK_VER%\config\sstep.ini %DBG_DIR%\*.*
REM copy %VERIFIND%\%VRF_VER%\data\beetle.res %SPFILES%\*.*
REM copy %SRC_ROOT%\Download\*.vft %SPFILES%\*.*
REM copy %SRC_ROOT%\Download\*.gra %SPFILES%\*.*
REM copy %SRC_ROOT%\Download\*.dld %SPDLD%\*.*

REM SERF Support
if %SERF_PRINT%. ==. goto :NoSERFPrint
REM copy %SRC_ROOT%\Download\serf.dlx %SPDLD%\print.dld
REM copy %SRC_ROOT%\Download\spanserf.dlx %SPDLD%\spanptr.dld
goto :DoneSerfDLD
:NoSERFPrint
REM copy %SRC_ROOT%\Download\tpl.dlx %SPDLD%\print.dld
REM copy %SRC_ROOT%\Download\spantpl.dlx %SPDLD%\spanptr.dld
:DoneSerfDLD

REM copy %SRC_ROOT%\Download\Export.TDD %SPEXPORT%\%SPOUTDIR%.*
REM copy %SRC_ROOT%\Download\dsoftpay.bat %SPDLD%\*.*
REM copy %SRC_ROOT%\VMAC\imm.ini %SPFILES%\*.*


REM -----  COPY PROJECT SPECIFIC FILES TO COMMON INCLUDE DIRECTORY  -----
@echo ***************************************
@echo Copying Required Project Specific Files
@echo ***************************************

REM SERF Host DLD Support
If %SP_SERF%. ==. goto :NoSERF
REM copy ..\Dld\sp%SP_PROJ%serf.dld %SPDLD%\sphost.dld
goto :HostDLDDone
:NoSerf
REM copy ..\Dld\sp%SP_PROJ%.dld %SPDLD%\sphost.dld
:HostDLDDone

if exist %SRC_ROOT%\include\sizes.h del %SRC_ROOT%\include\sizes.h
type %SRC_ROOT%\include\xsizes.h >> %SRC_ROOT%\include\sizes.h
type ..\proj\custsize.h >> %SRC_ROOT%\include\sizes.h
copy/v ..\proj\%SP_PROJ%proj.h %SRC_ROOT%\include\project.h
copy/y ..\Mdata\pfr.txt %SRC_ROOT%\powrfail\pfr.txt

rem copy/v ..\Export\*.tdf %SPEXPORT%\%SPOUTDIR%.tdf
rem copy/v ..\Export\*.xml %SPEXPORT%\%SPOUTDIR%.*
rem copy/v ..\Export\*.dtd %SPEXPORT%\*.*
if %BuildData%. ==d. goto :DATABUILD
goto :NOBUILD

REM -----  BUILD SOFTPAY 2000 DATA FILES
:DATABUILD
@echo *****************************
@echo Build SoftPay 2000 Data Files
@echo *****************************
REM goto :SPDATA
REM ----- FUNCTIONALITY TEST
REM goto :NOBUILD
REM echo call CreateMakFiles.bat -a -s %SERF_INCLUDES%
if %SP_HW%. ==ADS. call CreateMKFiles.bat -a -s%SERF_VER%
REM if %SP_HW%. ==ADS. call CreateMakFiles.bat -old -a -s%SERF_VER%
if NOT %SP_HW%. ==ADS. call CreateMKFiles.bat -s%SERF_VER%
REM goto :End

:SPDATA
@call spdata.bat
 
:NOBUILD

@echo ***********************************************************
@echo Copying Data File Generated Required Project Specific Files
@echo ***********************************************************

REM FORMATTER Print file support

if %SERF_PRINT%. ==. goto :FormatterPrint
goto :PrintFileDone
:FormatterPrint
if exist %SRC_ROOT%\Print\applic.h  del %SRC_ROOT%\Print\applic.h 
@copy ..\Tpl\applic.h %SRC_ROOT%\Print\*.*
if exist %SRC_ROOT%\Print\hostform.h del %SRC_ROOT%\Print\hostform.h
@copy ..\Tpl\hostform.h %SRC_ROOT%\Print\*.*
:PrintFileDone

if NOT %BuildData%.==d. goto COMPILE
if %BuildAll%. ==. goto :END

:COMPILE

@echo ************************************************
if %Build%.==a. echo Compiling ALL Softpay2000 Modules
if NOT %Build%.==a. echo Compiling ONLY modified Softpay2000 Modules
@echo ************************************************

REM ----- FUNCTIONALITY TEST
REM  goto :Link
REM _____IMAM __HERE_______
if %SP_HW%. ==ADS. SET RVCTBIN=C:\Progra~1\ARM\RVCT\Programs\2.0\155\win_32-pentium
REM __if %SP_HW%. ==ADS. SET RVCTBIN=C:\Progra~1\ARM\RVCT\Programs\2.0.1\277\win_32-pentium\backup_277
if %SP_HW%. ==SDS. SET SDS=C:\sds70
if %SP_HW%. ==SDS. SET RVCTBIN=C:\sds70\cmd
REM ---IMAM---CLOSE if %SP_HW%. ==SDS. H_DIRECTORY "\\SOFTPAY\\Ver30\\source\\verixinclude" 
REM --- imam make a Default if %SP_HW%. ==SDS. SET SDS_INCLUDES =C:\Softpay\VER30\SOURCE\verixinclude
if %SP_HW%. ==SDS. SET SDS_INCLUDES =C:\Softpay\VER30\SOURCE\include
REM _____IMAM __FINISH_______

REM --dbs  nmake /NOLOGO %BuildAll% /i /f%SRC_ROOT%\accum\accum%SP_HW%.mk
REM --dbs nmake /NOLOGO %BuildAll% /i /f%SRC_ROOT%\batch\batch%SP_HW%.mk
REM --dbs nmake /NOLOGO %BuildAll% /i /f%SRC_ROOT%\card\card%SP_HW%.mk
	REM --dbs nmake /NOLOGO %BuildAll% /i /f%SRC_ROOT%\check\check%SP_HW%.mk // no mk file
REM --dbs nmake /NOLOGO %BuildAll% /i /f%SRC_ROOT%\clerk\clerk%SP_HW%.mk
 nmake /NOLOGO %BuildAll% /i /f%SRC_ROOT%\comm\comm%SP_HW%.mk
REM --dbs nmake /NOLOGO %BuildAll% /i /f%SRC_ROOT%\common\common%SP_HW%.mk
REM --dbs nmake /NOLOGO %BuildAll% /i /f%SP_ROOT%\Projects\%SP_PROJ%\config\%SP_HW%\config.mk
REM --dbs nmake /NOLOGO %BuildAll% /i /f%SRC_ROOT%\control\contrl%SP_HW%.mk
	REM --dbs nmake /NOLOGO %BuildAll% /i /f%SRC_ROOT%\counter\counter%SP_HW%.mk
	REM --dbs nmake /NOLOGO %BuildAll% /i /f%SRC_ROOT%\EMV\emv%SP_HW%.mk
	REM --dbs nmake /NOLOGO %BuildAll% /i /f%SRC_ROOT%\iso8583\iso8583%SP_HW%.mk
REM --dbs nmake /NOLOGO %BuildAll% /i /f%SRC_ROOT%\ISODump\ISODump%SP_HW%.mk
REM 
REM --dbs nmake /NOLOGO %BuildAll% /i /f%SRC_ROOT%\main\main%SP_HW%.mk
REM --dbs nmake /NOLOGO %BuildAll% /i /f%SRC_ROOT%\merch\merch%SP_HW%.mk
REM --dbs nmake /NOLOGO %BuildAll% /i /f%SRC_ROOT%\msg\msg%SP_HW%.mk
REM --dbs	REM FAIL nmake /NOLOGO %BuildAll% /i /f%SRC_ROOT%\paramrpt\paramrpt%SP_HW%.mk
REM --dbs nmake /NOLOGO %BuildAll% /i /f%SRC_ROOT%\print\print%SP_HW%.mk
REM --dbs nmake /NOLOGO %BuildAll% /i /f%SRC_ROOT%\protocol\protocol%SP_HW%.mk
REM --dbs nmake /NOLOGO %BuildAll% /i /f%SRC_ROOT%\pinpad\pinpad%SP_HW%.mk
 REM --dbs nmake /NOLOGO %BuildAll% /i /f%SRC_ROOT%\pip\pip%SP_HW%.mk
REM --dbs nmake /NOLOGO %BuildAll% /i /f%SRC_ROOT%\powrfail\pfr%SP_HW%.mk
	REM FAIL nmake /NOLOGO %BuildAll% /i /f%SRC_ROOT%\Project\project%SP_HW%.mk
REM --dbs nmake /NOLOGO %BuildAll% /i /f%SRC_ROOT%\rcptcmpt\rcptcmpt%SP_HW%.mk
REM --dbs nmake /NOLOGO %BuildAll% /i /f%SRC_ROOT%\retry\retry%SP_HW%.mk
REM --dbs nmake /NOLOGO %BuildAll% /i /f%SRC_ROOT%\rs232com\rs232com%SP_HW%.mk
	REM FAIL nmake /NOLOGO %BuildAll% /i /f%SRC_ROOT%\settle\settle%SP_HW%.mk
REM --dbs nmake /NOLOGO %BuildAll% /i /f%SRC_ROOT%\shift\shift%SP_HW%.mk
REM --dbs nmake /NOLOGO %BuildAll% /i /f%SRC_ROOT%\stats\stats%SP_HW%.mk
REM --dbs nmake /NOLOGO %BuildAll% /i /f%SRC_ROOT%\tran\tran%SP_HW%.mk
REM --dbs nmake /NOLOGO %BuildAll% /i /f%SRC_ROOT%\ui\ui%SP_HW%.mk
REM --dbs nmake /NOLOGO %BuildAll% /i /f%SRC_ROOT%\utils\utils%SP_HW%.mk
REM --dbs nmake /NOLOGO %BuildAll% /i /f%SRC_ROOT%\vid\vid%SP_HW%.mk
REM --dbs nmake /NOLOGO %BuildAll% /i /f%SRC_ROOT%\ztconfig\ztconfig%SP_HW%.mk
REM --dbs nmake /NOLOGO %BuildAll% /i /f%SRC_ROOT%\ztexpress\ztexpress%SP_HW%.mk
REM --dbs nmake /NOLOGO %BuildAll% /i /f%SRC_ROOT%\codesec\seccode%SP_HW%.mk
	REM FAIL nmake /NOLOGO %BuildAll% /i /f%SRC_ROOT%\VMAC\VMAC%SP_HW%.mk
REM --dbs nmake /NOLOGO %BuildAll% /i /f%SRC_ROOT%\SPUCL\SPUCL%SP_HW%.mk
REM --dbsnmake /NOLOGO %BuildAll% /i /f\Softpay\%SP_VER%\HostSrc\UCL\UCL%SP_HW%.mk 
 REM --dbsnmake /NOLOGO %BuildAll% /i /f%SP_ROOT%\HostSrc\EMVsrc\EMVsrc%SP_HW%.mk
REM --dbs nmake /NOLOGO %BuildAll% /i /f\Softpay\%SP_VER%\HostSrc\CPACSrc\CPACsrc%SP_HW%.mk
 nmake /NOLOGO %BuildAll% /i /f\Softpay\%SP_VER%\HostSrc\UCL\UCL%SP_HW%.mk 
REM nmake /NOLOGO %BuildAll% /i /f\Softpay\%SP_VER%\HostSrc\AXAPSrc\AXAPsrc%SP_HW%.mk
REM nmake /NOLOGO %BuildAll% /i /f\Softpay\%SP_VER%\HostSrc\JCBISrc\JCBIsrc%SP_HW%.mk
REM nmake /NOLOGO %BuildAll% /i /f\Softpay\%SP_VER%\HostSrc\DINCSrc\DINCsrc%SP_HW%.mk
REM nmake /NOLOGO %BuildAll% /i /f\Softpay\%SP_VER%\HostSrc\BOCHSrc\BOCHsrc%SP_HW%.mk
	REM FAIL nmake /NOLOGO %BuildAll% /i /f\Softpay\%SP_VER%\HostSrc\EPPSrc\EPPsrc%SP_HW%.mk
	REM FAIL nmake /NOLOGO %BuildAll% /i /f\Softpay\%SP_VER%\HostSrc\CASHSrc\CASHSrc%SP_HW%.mk
	REM FAIL nmake /NOLOGO %BuildAll% /i /f\Softpay\%SP_VER%\HostSrc\CABKSrc\CABKSrc%SP_HW%.mk
REM nmake /NOLOGO %BuildAll% /i /f\Softpay\%SP_VER%\HostSrc\EPP1Src\EPP1src%SP_HW%.mk
REM nmake /NOLOGO %BuildAll% /i /f\Softpay\%SP_VER%\HostSrc\EPP2Src\EPP2src%SP_HW%.mk
REM nmake /NOLOGO %BuildAll% /i /f\Softpay\%SP_VER%\HostSrc\EPP3Src\EPP3src%SP_HW%.mk
REM nmake /NOLOGO %BuildAll% /i /f\Softpay\%SP_VER%\HostSrc\EPP4Src\EPP4src%SP_HW%.mk
REM nmake /NOLOGO %BuildAll% /i /f\Softpay\%SP_VER%\HostSrc\EPP5Src\EPP5src%SP_HW%.mk
REM nmake /NOLOGO %BuildAll% /i /f\Softpay\%SP_VER%\HostSrc\EPP6Src\EPP6src%SP_HW%.mk
REM nmake /NOLOGO %BuildAll% /i /f\Softpay\%SP_VER%\HostSrc\EPP7Src\EPP7src%SP_HW%.mk
   nmake /NOLOGO %BuildAll% /i /f\Softpay\%SP_VER%\HostSrc\IMAMSrc\IMAM%SP_HW%.mk
nmake /NOLOGO %BuildAll% /i /f%SP_ROOT%\projects\%SP_PROJ%\proj\%SP_PROJ%%SP_HW%.mk
  nmake /NOLOGO %BuildAll% /i /f\Softpay\%SP_VER%\HostSrc\%SP_PROJ%Src\%SP_PROJ%src%SP_HW%.mk

	REM --dbs nmake /NOLOGO %BuildAll% /i /f%SRC_ROOT%\dialer\dialer.mk

:LINK

if exist %DBG_DIR%\sp2000.*   del %DBG_DIR%\sp2000.*
if exist %DBG_DIR%\dialer.*   del %DBG_DIR%\dialer.*

if exist %SPFILES%\sp2000.*   del %SPFILES%\sp2000.*
if exist %SPFILES%\dialer.*   del %SPFILES%\dialer.*

@echo *****************************************
if %BuildAll%.== . @echo Linking ONLY modified Softpay2000 Modules
if %BuildAll%.==/a. @echo Linking ALL Softpay2000 Modules
@echo *****************************************

REM ----- FUNCTIONALITY TEST
REM goto :END

if %SP_HW%. ==ADS. goto :ADS_LINK
@echo nmake /NOLOGO %BuildAll% /i /f%SP_ROOT%\Projects\%SP_PROJ%\Bld\LinkSDS.mk
 nmake /NOLOGO %BuildAll% /i /f%SP_ROOT%\Projects\%SP_PROJ%\Bld\LinkSDS.mk
nmake /NOLOGO %BuildAll% /i /f%SP_ROOT%\Projects\%SP_PROJ%\Bld\LinkDialS.mk
goto :END
:ADS_LINK
  nmake /NOLOGO %BuildAll% /i /f%SP_ROOT%\Projects\%SP_PROJ%\Bld\LinkADS.mk
  nmake /NOLOGO %BuildAll% /i /f%SP_ROOT%\Projects\%SP_PROJ%\Bld\LinkDialA.mk

goto :END

:USAGE
CLS
ECHO.
ECHO    USAGE
ECHO    -----
ECHO    BUILD.BAT    Building targets for Omni Softpay Terminal application.
ECHO.
ECHO        Syntax: Build p1 p2 p3
ECHO.
ECHO               p1:
			  ARM - Build for Predator
ECHO               \a - Build all files
ECHO               \d - Build data files 
ECHO               \? - View Usage
ECHO               -? - View Usage
ECHO               ?  - View Usage
ECHO.
ECHO               p2:
			  ARM - Build for Predator
ECHO               \a - Build all files
ECHO               \d - Build data files 
ECHO               \? - View Usage
ECHO               -? - View Usage
ECHO               ?  - View Usage
ECHO.
ECHO               p3:
			  ARM - Build for Predator
ECHO               \a - Build all files
ECHO               \d - Build data files 
ECHO               \? - View Usage
ECHO               -? - View Usage
ECHO               ?  - View Usage
ECHO.
ECHO     *****  IMPORTANT NOTE:  This batch file must be executed from
ECHO                             .../Project/-Host- level of the Softpay
ECHO                             directory structure where the -Host-.DSP &
ECHO                             -Host-.DSW reside.
ECHO.
goto :END

:END
SET Build=
SET BuildData=
SET BuildAll=
SET SP_HW=

@echo Build.Bat Completed!
